<?php

class Update extends CI_Controller
{
	/**
	 * Default function that redirects the user to the login page in case no specific function is called.
	 *
	 * @param void
	 * @return void
	 */
	function index()
	{
		redirect('logon');
	}
	
	/**
	 * Function for activating users.
	 *
	 * @param string $username The username of the account that are to be activated.
	 * @param string $activation_code The activation code.
	 * @return void
	 */
	function activation($username = FALSE, $activation_code = FALSE)
	{
		//Determine if the user is loged in.
		if ($this->session->userdata('user_logedin')) {
			//If the user is loged in then redirect to start page.
			redirect('start');
		}
		else {
			//Loading page header and guest meny.
			$this->load->view('templates/v_header');
			$this->load->view('templates/v_menu_basic');
			
			//If some activation data is missing, then load view for failed activation.
			if ($username === FALSE || $activation_code === FALSE) {
				$this->load->view('pages/v_activation_fail');
			}
			else //If all activation data is present, do activation.
			{
				//Creating an user object.
				$this->load->model('m_user', 'user');
				
				//Try to activate the user.
				$result = $this->user->activate($username, $activation_code);
				
				//Decide what view to load based on the activation result.
				if ($result == 0) {
					$this->load->view('pages/v_activation_success');
				}
				else {
					//Loading the view.
					$this->load->view('pages/v_activation_fail');
				}
			}
			
			//Load page footer.
			$this->load->view('templates/v_footer');
		}
	}
	
	/**
	 * Function for recovering from forgotten password.
	 *
	 * @param string $username The username of the account which's password are to be updated.
	 * @param string $activation_code The update code.
	 * @return void
	 */
	function password($username = FALSE, $update_code = FALSE)
	{
		//TODO: Implement.
		
		die('Not implemented yet. Sorry!');
	}
	
	/**
	 * Function for activating an updated email adress.
	 *
	 * @param string $username The username of the account which's email are to be updated.
	 * @param string $activation_code The update code.
	 * @return void
	 */
	function email($username = FALSE, $update_code = FALSE)
	{
		//TODO: Implement.
		
		die('Not implemented yet. Sorry!');
	}
}
?>